// ***********************************************************************
// Table C2: Building footprint over parcel size by NAICS 3-digit industry
// ***********************************************************************

// Writes the results as reg_montreal to $resultpath/tables/

use "$outpath/database_for_reg.dta", clear

eststo clear

gen parc_cov = B_area_c/P_area_c
label var parc_cov "Building footpring over parcel size"

reghdfe ratio Lnpopcma Lnareacma dist_min_NEW i.cat0 spacematep spacematep2 spacematep3 spacematep4 if samplep==1, absorb(naics4d eruid) cluster(cmauid)

keep if e(sample)==1&parc_cov<1

tostring naics3d, replace

replace naics3d="311 Food manufacturing" if naics3d=="311"
replace naics3d="312 Beverage product manuf." if naics3d=="312"
replace naics3d="313 Textile mills" if naics3d=="313"
replace naics3d="314 Textile product mills" if naics3d=="314"
replace naics3d="315 Clothing manufacturing" if naics3d=="315"
replace naics3d="316 Leather, allied product manuf." if naics3d=="316"
replace naics3d="321 Wood product manufacturing" if naics3d=="321"
replace naics3d="322 Paper manufacturing" if naics3d=="322"
replace naics3d="323 Printing, support activities" if naics3d=="323"
replace naics3d="324 Petrol, coal product manuf." if naics3d=="324"
replace naics3d="325 Chemical manufacturing" if naics3d=="325"
replace naics3d="326 Plastics, rubber products manuf." if naics3d=="326"
replace naics3d="327 Non-metallic mineral product manuf." if naics3d=="327"
replace naics3d="331 Primary metal manufacturing" if naics3d=="331"
replace naics3d="332 Fabricated metal product manuf." if naics3d=="332"
replace naics3d="333 Machinery manufacturing" if naics3d=="333"
replace naics3d="334 Computer, electronic product manuf." if naics3d=="334"
replace naics3d="335 Electrical, appliance manuf." if naics3d=="335"
replace naics3d="336 Transportation equipment manuf." if naics3d=="336"
replace naics3d="337 Furniture, related product manuf." if naics3d=="337"
replace naics3d="339 Miscellaneous manufacturing" if naics3d=="339"

preserve

collapse (count) obs=parc_cov (mean) meannaics3d=parc_cov (p50) p50naics3d=parc_cov (sd) cvnaics3d=parc_cov, by(naics3d)
replace cvnaics3d=cvnaics3d/meannaics3d
tostring naics3d, replace
save "$resultpath/tables/stat_parc_cov_naics.dta", replace

restore

preserve

collapse (count) obs=parc_cov (mean) meannaics3d=parc_cov (p50) p50naics3d=parc_cov (sd) cvnaics3d=parc_cov
replace cvnaics3d=cvnaics3d/meannaics3d
gen naics3digit="Total"
append using "$resultpath/tables/stat_parc_cov_naics.dta"
order naics3d obs mean p50 cv
sort naics3d

foreach v of var mean p50 cv{
replace `v'=round(`v',0.01)
}

save "$resultpath/tables/stat_parc_cov_naics.dta", replace

restore

